package xyz.xuminghai.javafx_learn.scene.shape;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.NodeOrientation;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

/**
 * 2023/8/3 14:54 星期四<br/>
 * Text类定义显示文本的节点。段落由'\n'分隔，并且文本在段落边界上换行。
 *
 * @author xuMingHai
 */
public class TextApp extends Application {

    private final HBox hBox = new HBox(30.0);

    private final BorderPane root = new BorderPane(hBox);


    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        Text text1 = new Text("望岳");
        text1.setFont(Font.font("华文行楷", 30.0));
        text1.setWrappingWidth(text1.getFont().getSize());

        Text text2 = new Text("（唐）");
        // 因为使用了反向绘制
        text2.setTranslateX(-15.0);
        text2.setFont(Font.font("华文行楷", 20.0));

        Text text3 = new Text("杜甫");
        text3.setTranslateX(5.0);
        text3.setFont(Font.font("华文行楷", 20.0));
        text3.setWrappingWidth(text3.getFont().getSize());

        Text text4 = new Text("岱宗夫如何？齐鲁青未了。");
        text4.setFont(Font.font("华文行楷", 30.0));
        text4.setWrappingWidth(text4.getFont().getSize());

        Text text5 = new Text("造化钟神秀，阴阳割昏晓。");
        text5.setFont(Font.font("华文行楷", 30.0));
        text5.setWrappingWidth(text5.getFont().getSize());

        Text text6 = new Text("荡胸生曾云，决眦入归鸟。");
        text6.setFont(Font.font("华文行楷", 30.0));
        text6.setWrappingWidth(text6.getFont().getSize());

        Text text7 = new Text("会当凌绝顶，一览众山小。");
        text7.setFont(Font.font("华文行楷", 30.0));
        text7.setWrappingWidth(text7.getFont().getSize());

        hBox.getChildren().addAll(new VBox(20.0, text1,
                        new VBox(5.0, text2, text3)),
                text4, text5, text6, text7);
        hBox.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
        BorderPane.setMargin(hBox, new Insets(50.0));
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }


}
